package com.kaigejava.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Controller
public class HomeController {
    @RequestMapping(value = "/")
    public String index(){
        log.info("===>>访问index");
        return "views/index";
    }

    @RequestMapping(value = "/welcome")

    public String home(){
        log.info("===>>访问home");
        return "views/welcome";
    }

    @RequestMapping("/getUserMsgJsonp")
    @ResponseBody
    public String getUserMsgJsonp(HttpServletRequest request, String callback,Integer userId){
        log.info("==callback:{},userId:{}",callback,userId);
        String result =callback+"(";
        Map<String,Object> map = new HashMap<>();
        map.put("id",userId);
        map.put("name","用户名是"+userId);
        String str = JSON.toJSONString(map);
        //  result=callback+"("+result+")";
        result += str;
        result+=")";
        return result;
    }
}